﻿<%@ page language="java" import="java.util.*"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
String path = request.getContextPath();
String app_version = net.zoneland.greenleaf.GLOBAL.APP_VERSION;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=10;IE=9;IE=8;" />	
  		<!-- Title and other stuffs -->
  		<title>后台管理系统</title> 
  		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  		<script src="<%=path %>/js/greenleaf/jquery-1.8.3.js"></script> <!-- jQuery -->		
  		<script type="text/javascript">
	  		var path = "<%=path %>";
	  		var jobid = "<%=request.getQueryString()%>";
	  		var app_version = "<%=app_version %>";
	  		if( jobid.split("=").length > 1 ){
	  			jobid = jobid.split("=")[1];
	  		}
  		</script>
 </head>
 <body>
<div id="mainbar" class="mainbar">
 <!-- Page heading -->
	<div class="page-head">
	    <h2 class="pull-left"><i class="icon-home"></i> 任务信息详情</h2>
        <!-- Breadcrumb -->
        <div class="bread-crumb pull-right">
          <a href="javascript:void()"><i class="icon-home"></i> 定时任务管理</a> 
          <!-- Divider -->
          <span class="divider">/</span> 
          <a href="javascript:void()" class="bread-current">任务信息详情</a>
        </div>
        <div class="clearfix"></div>
	</div>
	<!-- Page heading ends -->

	<!-- Matter -->
	<div class="matter">
        <div class="container">
        <!-- 页面的内容开始. -->
        <div class="row">
            <div class="col-md-12">
              <div class="widget wgreen">
                <div class="widget-content">
                  <div class="padd">
                    <h6>时间表达款示例</h6>
                    <hr />                    
                    <table width="100%" border=0>							
							<thead>
								<tr>
								   <td align="right" width="150"  style="color:orange">"0 0 12 * * ? "</td>
								   <td align="left">每天12点运行</td>
								   <td align="right" width="150"  style="color:orange">"0 15 10 ? * *"</td>
								   <td align="left">每天10:15运行</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 15 10 * * ? 2008"</td>
								   <td align="left">在2008年的每天10：15运行</td>
								   <td align="right" style="color:orange">"0 * 14 * * ?"</td>
								   <td align="left">每天14点到15点之间每分钟运行一次，开始于14:00，结束于14:59。</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 0-5 14 * * ?"</td>
								   <td align="left">每天14:00点到14:05，每分钟运行一次。</td>
								   <td align="right" style="color:orange">"0 10,44 14 ? 3 WED"</td>
								   <td align="left">3月每周三的14:10分到14:44，每分钟运行一次。</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 15 10 L * ?"</td>
								   <td align="left">每月最后一天10:15分运行。</td>
								   <td align="right" style="color:orange">"0 15 10 ? * 6L"</td>
								   <td align="left">每月最后一个星期五10:15分运行。</td>
								</tr>
								<tr>
								   <td align="right"  width="120" style="color:orange">"0 15 10 * * ? *"</td>
								   <td align="left">每天10:15运行</td>
								   <td align="right" style="color:orange">"0 0/5 14,18 * * ?"</td>
								   <td align="left">每天14点到15点每5分钟运行一次，此外每天18点到19点每5钟也运行一次。</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 15 10 ? * 6#3"</td>
								   <td align="left">每月第三个星期五的10:15分运行。</td>
								   <td align="right"  width="120" style="color:orange">"0 15 10 * * ?"</td>
								   <td align="left">每天10:15运行</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 0/5 14 * * ?"</td>
								   <td align="left">每天14点到15点每5分钟运行一次，开始于14:00，结束于14:55。</td>
								   <td align="right" style="color:orange">"0 15 10 ? * MON-FRI"</td>
								   <td align="left">每周一，二，三，四，五的10:15分运行。</td>
								</tr>
								<tr>
								   <td align="right" style="color:orange">"0 15 10 ? * 6L 2007-2009"</td>
								   <td align="left">在2007,2008,2009年每个月的最后一个星期五的10:15分运行。</td>
								   <td align="right" style="color:orange">"0 15 10 15 * ?"</td>
								   <td align="left">每月15日10:15分运行。</td>
								</tr>
							</thead>
						</table>
                  </div>
                   <div class="padd">
                    <h6>定时任务详情</h6>
                    <hr />
                    <!-- Form starts.  -->
                     <form class="form-horizontal" role="form">
                     	  <input id="jobid" type="hidden" value="0"/>
                          <div class="form-group">
                               <label class="col-lg-3 control-label">任务名称</label>
                               <div class="col-lg-3">
                                   <input id="jobname" type="text" class="form-control" placeholder="请填写任务名称">
                               </div>
                               <label class="col-lg-3 control-label">时间表达式</label>
                               <div class="col-lg-3">
                                   <input id="cronexpression" type="text" class="form-control" placeholder="请填写任务执行时间表达式">
                               </div>
                          </div>
                          <div class="form-group">
                               <label class="col-lg-4 control-label">任务实现类</label>
                               <div class="col-lg-8">
                                   <input id="beanclass" type="text" class="form-control" placeholder="请填写任务实现类名">
                               </div>
                          </div>
                          <div class="form-group">
                               <label class="col-lg-3 control-label">执行主机IP</label>
                               <div class="col-lg-3">
                                   <input id="run_hostname" type="text" class="form-control" placeholder="请填写执行主机的IP地址">
                               </div>
                               <label class="col-lg-3 control-label">是否启用</label>
                               <div class="col-lg-3">
                                    <select id="jobstatus" class="form-control">
                                      <option value="1">启用</option>
                                      <option value="0">停用</option>
                                    </select>
                                  </div>
                          </div>
                          <div class="form-group">
                                  <label class="col-lg-4 control-label">备注信息</label>
                                  <div class="col-lg-8">
                                    <textarea id="description" class="form-control" rows="3" placeholder="请填写备注信息"></textarea>
                                  </div>
                          </div>              
                          <hr />
                          <div class="form-group">
                                  <div class="col-lg-offset-1 col-lg-9">
                                    <button name="btn_timer_save" type="button" class="btn btn-primary">保存信息</button>
                                    <button name="btn_timer_reset" type="button" class="btn btn-primary">重置信息</button>
                                    <button name="btn_timer_delete" type="button" class="btn btn-danger" disabled="true">删除信息</button>
                                  </div>
                           </div>
                       </form>
                  </div>
                </div>
                <div class="widget-foot"></div>
              </div>
            </div>
          </div>
        <!-- 页面的内容结束. -->
        </div>
	</div>
	<!-- Matter ends -->
</div>
<!-- jQuery Flot -->
<script src="<%=path %>/js/greenleaf/actions/timer_action.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	view_timer_info("first");
	
	$("[name='btn_timer_save']").click(function(){
		save_timer_info();
	});
	
	$("[name='btn_timer_reset']").click(function(){
		$("form")[0].reset();
	});
	
	$("[name='btn_timer_delete']").click(function(){
		delete_timer_info();
	});
	
});
	
function view_timer_info(){
	if( jobid == "null" ||jobid == null || jobid == undefined || jobid == "0" ){
		return false;
	}
	//说明是查询
	$("#jobid").val(jobid);
	$("[name='btn_timer_delete']").attr("disabled", false);
	//$("#jobname").attr("readonly", true);
	var url = timer_info_action.service.get +"/"+ jobid;
	$.ajax({
		  url: url,
		  type : 'get',
		  async : false,
		  contentType: "application/json; charset=utf-8",
		  dataType: "json",
		  success: function(json) {
			//向页面上加载信息
				if(json && json.data ){
					var t_info = json.data;
					$("#jobid").val(t_info.jobid);
					$("#jobname").val(t_info.jobname );
			 		$("#beanclass").val(t_info.beanclass);
			 		$("#cronexpression").val(t_info.cronexpression);
			 		$("#jobstatus").val(t_info.jobstatus);
			 		$("#description").val(t_info.description);
			 		$("#run_hostname").val(t_info.run_hostname);
				}	
		  }
	});
}

function save_timer_info(){
	var timer_info = {};
	timer_info.jobid = $("#jobid").val();
	timer_info.jobname = $("#jobname").val();
	timer_info.beanclass = $("#beanclass").val();
	timer_info.cronexpression = $("#cronexpression").val();
	timer_info.run_hostname = $("#run_hostname").val();
	timer_info.jobstatus = $("#jobstatus").val();
	timer_info.description = $("#description").val();	
	var json_data = JSON.stringify( timer_info );
	var url = timer_info_action.service.save;
	$.ajax({
		  url: url,
		  type : 'post',
		  async : false,
		  data: json_data,
		  contentType: "application/json; charset=utf-8",
		  dataType: "json",
		  success: function(json) {
			 alert(json.message);
			loadPage(timer_info_action.page.list);
		  }
	});
}

function delete_timer_info(){
	var jobid = $("#jobid").val();
	var url = timer_info_action.service.remove;
	if(confirm("您确定需要删除定时任务吗？数据删除后将无法恢复。")){
		if(jobid!=null && jobid!="0" && jobid.length>0){
	        if(jobid!="" && jobid.length>0){        	
		        $.getJSON(url, {"id":jobid}, function(json){
					alert(json.message);
					loadPage(timer_info_action.page.list);
				});
	        }      
		}
	}
}

</script>
</body>